import {request} from "./index"
/** 砍价商品列表
 * 
 * @param {number} page
 * @param {string} goodsName 
 * @param {string} token
 */
const getKanJiaGoods = (page, goodsName, token) => {
  return request.get("v1/app/promotion/kanjiaGoods", {
    page,
    size: 20,
    goodsName
  },{
    'Authorization': token
  })
}

/** 发起砍价
 * 
 * @param {string} id 
 * @param {string} token 
 */
const sendKanJia = (id, token) => {
  return request.post(`v1/app/promotion/kanjiaGoods/${id}`, {}, {
    'Authorization': token,
    'content-type': 'application/x-www-form-urlencoded;charset=UTF-8'
  })
}

/** 帮砍一刀
 * 
 * @param {string} kanjiaActivityId 
 * @param {string} token 
 */
const helpKanJia = (kanjiaActivityId, token) => {
  return request.post(`v1/app/promotion/kanjiaGoods/help/${kanjiaActivityId}`, {}, {
    'Authorization': token,
    'content-type': 'application/x-www-form-urlencoded;charset=UTF-8'
  })
}

/** 获取砍价活动
 * 
 * @param {string} id 
 * @param {string} token 
 */
const getKanJia = (kanjiaActivityId, token) => {
  console.log(kanjiaActivityId)
  return request.post(`v1/app/promotion/kanjiaGoods/getKanjiaActivity`, {
    kanjiaActivityId,
    promotionStatus: 'START'
  }, {
    'Authorization': token,
    'content-type': 'application/x-www-form-urlencoded;charset=UTF-8'
  })
}

/** 获取帮砍记录
 * 
 * @param {string} kanJiaActivityId 
 * @param {number} page 
 * @param {string} token 
 */
const getHelpList = (kanJiaActivityId, page, token) => {
  return request.get(`v1/app/promotion/kanjiaGoods/getKanjiaActivity/logs`, {
    kanJiaActivityId,
    page,
    size: 20
  }, {
    'Authorization': token
  })
}

/** 获取我的砍价记录
 * 
 * @param {number} page 
 * @param {string} token 
 */
const getMyKanJiaList = (page, token) => {
  return request.get(`v1/app/promotion/kanjiaGoods/getKanjiaActivity/logs`, {
    page,
    size: 20
  }, {
    'Authorization': token
  })
}


export {
  getKanJiaGoods,
  sendKanJia,
  helpKanJia,
  getKanJia,
  getHelpList,
  getMyKanJiaList
}